/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'type',
        type: 'int',
        hideQuery:true,
        hideQueryType:'eq',
        hideQueryValue:3,
        hide:true
    },
    {
        id: 'id',
        title: '编号',
        type: 'string',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },

    {
        id: 'name',
        title: '用户名',
        type: 'string',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'type',
        title: '类型',
        type: 'string',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable: {
            1: $lang.adminType.T1,
            2: $lang.adminType.T2,
            3: $lang.adminType.T3,
        }
    },
    {
        id: 'operation',
        title: '管理操作',
        type: 'string',
        columnClass: 'text-center',
        fastSort: false,
        extra: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var  html ="";
            if($("#adminBindCancel")&&$("#adminBindCancel").val() == 1) {
                html += "<a href='javascript:;' class='btn btn-danger btn-sm m-r-10' onclick='OperateHandle.delAdmin(" + record.id + ",\"" + record.name + "\")'><i class='fa fa-trash-o'></i>&nbsp;删除&nbsp;</a>";
            }
            return html;
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'agent/json/adminList',
    exportFileName: '绑定后台管理员列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["id","type"]}
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = {};

//默认查询条件
grid.fastQueryParameters = {};
grid.fastQueryParameters['eq_delFlag'] = 1;
grid.fastQueryParameters['eq_type'] = 3;
//排序
grid.sortParameter.columnId = 'id';
grid.sortParameter.sortType = 0;
//列表结束

//操作处理开始
var OperateHandle = function () {

    //删除Url
    var delUrl = ncGlobal.adminRoot + "agent/json/cancel";

    /**
     * 删除借款标
     */
    function _delAdmin(id, content) {
        var tpl = '您选择对绑定的用户<strong>' + content + '</strong> 进行删除操作，删除后将无法恢复。<br/>您确定要进行删除操作吗?'
        $.ncConfirm({
            url: delUrl,
            data: {
                id: id
            },
            content: tpl,
            alertTitle: "删除操作"
        });
    }

    function _bindEvent() {

        //新增对话框初始化
        $("#addModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm").psly().reset();

            $.each($("#addForm input"),function (i, v) {
                $(v).val('');
            })
        });


        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters['lk_name'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }


    //外部可调用
    return {
        bindEvent: _bindEvent,
        delAdmin: _delAdmin
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});